import { loginF } from "./login.js";
import { loginC } from "./code.js";
import * as obj from "../public.js";
import './showH.js';
import { cookie } from "../../public/cookieFnNew.js";
import { codeF } from "../register/codeAjax.js";
const o = obj.default;
// 手机号正则
const tel = o.$('.tel') ? o.$('.tel') : '';
const telD = o.$('#telD')
const testL = o.$('.testL')
const pwd = o.$('.pwdL')
const rf = o.$('.rf')
const uname = o.$('.uname');
const password = o.$('.password');
const regTel = /^1[2-9]\d{9}$/;
console.log(pwd)
if (tel) {
  let falg;
  testL.style.display = '';
  pwd.style.display = 'node'
  rf.style.display = 'none'
  const have = o.$('.have')
  tel.onchange = function () {
    if (regTel.test(tel.value)) {
      tel.parentNode.nextElementSibling.innerHTML = '√'
      falg = true
    } else {
      tel.parentNode.nextElementSibling.innerHTML = '手机号格式不对'
      falg = false
    }
    if (falg) {
      have.onclick = function () {
        codeF(tel.value)
      }
    }
  }
  const code = have.nextElementSibling
  o.$('.log').onclick = function () {
    if (falg && code.value) {
      loginC()
    }
    if (!!(uname.value && password.value)) {
      loginF()
    }
  }
}

const mima = o.$('#mima');
mima.onclick = function () {
  testL.style.display = 'none';
  pwd.style.display = '';
  console.log(pwd.style.display)
  rf.style.display = '';
  mima.className = 'b_bottom';
  telD.className = '';
  const petU = cookie.getCookie('petUserD') ? cookie.getCookie('petUserD') : '';

  const rempwd = o.$('.rempwd')
  const p = petU.split(',')
  p.some(val => {
    if (val.split(':')[0] === 'username') {
      uname.value = val.split(':')[1]
    }
    if (val.split(':')[0] === 'password') {
      password.value = val.split(':')[1]
      rempwd.checked = true;
    }
  })
}
console.log(telD)
telD.onclick = function () {
  testL.style.display = '';
  pwd.style.display = 'none';
  rf.style.display = 'none';
  mima.className = '';
  telD.className = 'b_bottom';
}
 const show = o.$('#show')
 const text = show.previousElementSibling
 console.log(text)
 show.onclick = function (){console.log(show)
  if(show.className.indexOf('hidden') !== -1){
    show.className = 'iconfont icon-yanjing_xianshi_o show'
    text.type = 'text'
  }else{
    show.className = 'iconfont icon-yanjing_yincang_o hidden'
    text.type = 'password'
  }
 }





